/*
 * @(#)XfsimPlotFrame.java        2003/01/01
 *
 * This file is part of Xfuzzy 3.0, a design environment for fuzzy logic
 * based systems.
 *
 * (c) 2000 IMSE-CNM. The authors may be contacted by the email address:
 *                    xfuzzy-team@imse.cnm.es
 *
 * Xfuzzy is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation.
 *
 * Xfuzzy is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */


package xfuzzy.xfsim.model;

import xfuzzy.lang.*;
import xfuzzy.xfsim.view.IXfsimFrame;
import xfuzzy.xfsim.view.Xfsim;
import xfuzzy.xfsim.view.listener.*;
import javax.swing.*;
import java.awt.*;

/**
 * Clase que desarrolla un panel de representaci�n gr�fica de dos
 * variables de la simulaci�n
 * 
 * @author Francisco Jos� Moreno Velo
 *
 */
public class XfsimPlotFrame extends JDialog implements IXfsimFrame {
	
	//----------------------------------------------------------------------------//
	//                            COSTANTES PRIVADAS                              //
	//----------------------------------------------------------------------------//

	/**
	 * C�digo asociado a la clase serializable
	 */
	private static final long serialVersionUID = 95505666603061L;
	
	//----------------------------------------------------------------------------//
	//                            MIEMBROS PRIVADOS                               //
	//----------------------------------------------------------------------------//
	
	/**
	 * Ventana principal de la aplicaci�n
	 */
	private JFrame frame;

	/**
	 * Panel a representar en el di�logo
	 */
	private XfsimPlotPanel panel;
	
	//----------------------------------------------------------------------------//
	//                                CONSTRUCTOR                                 //
	//----------------------------------------------------------------------------//
	
	/**
	 * Constructor
	 */
	public XfsimPlotFrame(JFrame frame, XfsimPlot config, Specification spec) {
		super(frame,config.toString(),false);
		this.frame = frame;
		this.panel = new XfsimPlotPanel(config,spec);

		Container content = getContentPane();
		content.add(panel);
		
		setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
		addWindowListener(new XfsimWindowListener(this));
		setSize(600,450);
		setVisible(true);
	}
	
	//----------------------------------------------------------------------------//
	//                             M�TODOS P�BLICOS                               //
	//----------------------------------------------------------------------------//
	
	/**
	 * Muestra la representaci�n gr�fica
	 */
	public void open() {
		setVisible(true);
	}
	
	/**
	 * Dibuja un nuevo punto de la representaci�n
	 */
	public void iter(XfsimStatus status) {
		int iter = status.getIteration();
		double time = status.getTime();
		double[] fzst = status.getFuzzyInputs();
		double[] ptst = status.getFuzzyOutputs();

		this.panel.iter(iter, time, fzst, ptst);
	}

	/**
	 * Acci�n de cerrar la ventana
	 */
	public void close() {
		if(frame != null){
			Xfsim xfsim = (Xfsim) frame;
			if(xfsim.isSimulating()) return;
		}
		this.setVisible(false);
	}

}
